package com.tefl.service.impl;

import javax.annotation.Resource;

import com.tefl.common.util.ValidateHelper;
import com.tefl.dao.AdministratorDao;
import com.tefl.entity.Administrator;
import com.tefl.service.AdministratorService;

/**
 * 管理员业务接口实现类
 * @author liuxin
 *
 */
public class AdministratorServiceImpl implements AdministratorService {
	
	@Resource
	private AdministratorDao adminDao;

	/**
	 * 管理员登陆校验业务
	 * @param adminName 管理员登陆名称
	 * @param password 管理员登陆密码
	 * @return 校验通过返回true,反之false
	 * @throws Exception 校验不通过异常
	 */
	@Override
	public Administrator login(String adminName, String password) throws Exception {

		if (ValidateHelper.isEmptyString(adminName)) {
			throw new Exception("请输入登陆帐号.");
		}

		Administrator admin = adminDao.getAdministratorByName(adminName);

		if (null == admin) {
			throw new Exception("帐号不存在，请重新输入.");
		}

		if (!admin.getAdmin_password().equals(password)) {
			throw new Exception("密码错误，请重新输入.");
		}

		return admin;
	}

}
